﻿using UnityEngine;
using UnityEngine.Extension;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Extension;
[Serializable]
public class CommandSubject
{
    public UnityEngine.Object content;
    public string methodPath = string.Empty;
    public object o_content = null;
    public List<Parameter> m_parameters;
    public void SetObject(object item)
    {
        o_content = item;
    }

    object Content
    {
        get
        {
            object result = null;
            if (content.isNotNone())
                result = content;
            else if (o_content.isNotNull())
                result = o_content;
            return result;
        }
    }

    public void SetParamObject(object obj)
    {
        m_parameters.ForEach(p => { if (!p.source) p.SetObject(obj); });
    }
    public object[] parameters { get { return Parameter.GetParameters(m_parameters); } }

    public void Invoke()
    {

        if (Content.isNotNull() && methodPath.isNotEmpty())
        {
//            Debug.Log("On Invoke");
            Content.InvokeMethod(methodPath, parameters);
        }
    }
}
